
  class TreeNode {
      int val;
      TreeNode left;
      TreeNode right;
      TreeNode() {}
      TreeNode(int val) { this.val = val; }
     TreeNode(int val, TreeNode left, TreeNode right) {
          this.val = val;
          this.left = left;
          this.right = right;
        }
 }

class Solution {
    int count = 0;
    public int countNodes(TreeNode root) {
        //前序遍历(遍历思路)
//        if(root == null){
//            return 0;
//        }
//        count++;
//        countNodes(root.left);
//        countNodes(root.right);
//        return count;
        //子问题思路
        if(root == null){
            return 0;
        }
        return countNodes(root.left) + countNodes(root.right) + 1;
    }
}